using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ColladaToData
{
	public static class ByteConversion
	{
		public static Byte[] ToByteArray(float[] data)
		{
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

			foreach (float val in data)
			{
				writer.Write(val);
			}

			byte[] byteArray = new byte[stream.Length];
			stream.Seek(0, System.IO.SeekOrigin.Begin);

			stream.Read(byteArray, 0, (int)stream.Length); // Make sure stream isn't too long, might want to check Length vs. int.MaxValue
			stream.Close();
			return byteArray;
		}

		public static Byte[] ToByteArray(UInt32[] data)
		{
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

			foreach (UInt32 val in data)
			{
				writer.Write(val);
			}

			byte[] byteArray = new byte[stream.Length];
			stream.Seek(0, System.IO.SeekOrigin.Begin);

			stream.Read(byteArray, 0, (int)stream.Length); // Make sure stream isn't too long, might want to check Length vs. int.MaxValue
			stream.Close();
			return byteArray;
		}

		public static Byte[] ToByteArray(UInt16[] data)
		{
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

			foreach (UInt16 val in data)
			{
				writer.Write(val);
			}

			byte[] byteArray = new byte[stream.Length];
			stream.Seek(0, System.IO.SeekOrigin.Begin);

			stream.Read(byteArray, 0, (int)stream.Length); // Make sure stream isn't too long, might want to check Length vs. int.MaxValue
			stream.Close();
			return byteArray;
		}

		public static Byte[] ToByteArray(bool[] data)
		{
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);

			foreach (bool val in data)
			{
				writer.Write(val);
			}

			byte[] byteArray = new byte[stream.Length];
			stream.Seek(0, System.IO.SeekOrigin.Begin);

			stream.Read(byteArray, 0, (int)stream.Length); // Make sure stream isn't too long, might want to check Length vs. int.MaxValue
			stream.Close();
			return byteArray;
		}
	}
}
